/**
 * Created by Intellij IDEA
 *
 * @author 王俊凯
 * @Date: 2023/2/28 20:38
 * @Version 1.0
 */
package com.eight.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.eight.pojo.BaseArea;
import com.eight.pojo.TbShop;
import com.eight.service.BaseAreaService;
import com.eight.service.CarShopService;
import com.eight.vo.CarVo;
import com.eight.vo.ComResult;
import com.eight.vo.MyObjectUtils;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/rent/shop")
public class CarShopController {

    @Autowired
    private CarShopService carShopService;

    @Autowired
    private BaseAreaService baseAreaService;

    @RequestMapping("/list")
    public ComResult list(@RequestBody CarVo carVo){
        if (MyObjectUtils.objectCheckIsNull(carVo)) {
            ComResult selectCarShop = carShopService.selectCarShop();
            return selectCarShop;
        }
        ComResult selectCarShop = carShopService.selectCarShop(carVo);
        return selectCarShop;
    }

    @RequestMapping("/insert")
    public ComResult insert(@RequestBody TbShop tbShop){
        ComResult insertCarShop = carShopService.insertCarShop(tbShop);
        return insertCarShop;
    }

    @RequestMapping("/delete")
    public ComResult delete(int id){
        ComResult deleteCarShop = carShopService.deleteCarShop(id);
        return deleteCarShop;
    }

    @RequestMapping("/update")
    public ComResult update(@RequestBody TbShop tbShop){
        ComResult updateCarShop = carShopService.updateCarShop(tbShop);
        return updateCarShop;
    }

    /**
     * 根据地区查询门店
     * @return
     */
    @RequestMapping("/selectByAddress/{a}/{b}/{c}")
    public ComResult selectByAddress(@PathVariable Integer a, @PathVariable Integer b, @PathVariable Integer c){
        ComResult selectByAddress = carShopService.selectByAddress(new TbShop().setProvinceId(a).setCityId(b).setAreaId(c));
        return selectByAddress;
    }
    /**
     * 根据id查询车辆
     * @param shopId
     * @return
     */
    @RequestMapping("/selectByName")
    public ComResult selectByName(Integer shopId){
        ComResult selectByName = carShopService.selectByCarName(shopId);
        return selectByName;
    }

}

